<template>
  <div class="login-container">
    <div class="input-container">
      <div class="top-information">欢迎您，请登录</div>
      <div class="input-warpper">
        <span></span><input class="input-content" placeholder="用户名" type="input" autocomplete="off" v-model="userName">
      </div>
      <div class="input-warpper">
        <span></span><input class="input-content" placeholder="密码" type="password" autocomplete="off"
                            v-model="password">
      </div>
      <button class="commit" @click="toLogin">登录</button>
      <div class="foot-tip">如果忘记密码，请联系管理员重置。</div>
    </div>
  </div>
</template>

<script>
import "@/css/login.less"
import {mapActions} from 'vuex';
import axios from "axios";
import Cookies from 'js-cookie'

//拦截响应进行处理设置
axios.interceptors.response.use(response => {
  const setCookieHeader = response.headers['cookie-value'];
  console.log("test1:=" + setCookieHeader);
  if (setCookieHeader) {
    //手动设置cookie  path:匹配的路径   domain的含义为域,分为子域和父域，子域可以访问本级域名及父级域名的下的cookie
    //假设有两个域名a.b.e.f.com.cn  以下用域名1指代此域名      c.d.e.f.com.cn   以下用域名2指代此域名
    //在域名中，所有域名进行分级，也就是说域名1与域名2都是f.com.cn的子域名，f.com.cn又是com.cn的子域名(参考：https://zhuanlan.zhihu.com/p/652236393?utm_id=0)
    // cookie匹配规则：先获取当前域名以及父域名下的cookie，然后再根据path匹配具体的cookie，当然这里面如果有多个cookie还有一定的优先级筛选规则
    Cookies.set('authorization-project', setCookieHeader, {expires: 1/*, path: "/", domain: "127.0.0.2"*/});
  }
  return response;
}, error => {
  return Promise.reject(error);
});

export default {
  data() {
    return {
      userName: "",
      password: "",
    }
  },
  created() {

  },
  mounted() {

  },
  methods: {
    ...mapActions({
      saveUserInfo: 'saveUserInfo'
    }),
    toLogin: function () {
      let me = this;
      var options = {
        url: '/authorizationProject/doLogin?userName=' + me.userName + '&passWord=' + me.password,
        method: 'post',
        headers: {'Content-Type': 'application/x-www-form-urlencoded', 'SameSite': 'None'}
      }
      axios(options).then(function (res) {
        console.log(res);
        console.log(res.data.code);
        alert(res.data.msg);
        //根据返回的验证码是否成功进行重定向
      })
    }
  }
}
</script>

<style lang="css">

</style>
